/*
 
 * * author : Mishal Parmar
 *  Date: 20 Oct 2012
 */
package dbhandler;

import java.sql.SQLException;
import entityclasses.event;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author admin
 */
public class EventManage {
    
public ArrayList eventviewbyid(int id) throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "select * from tbl_event where event_id="+id;
  
        
        
        DBConnection db = new DBConnection();
        ArrayList<event> event=new ArrayList<event>();
        ResultSet rs;
        
        db.connect();
        try {
            rs=db.customQuery(Query);
                      
            
           while(rs.next()){
                event evt=new event();
                evt.setEventId(Integer.parseInt(rs.getString(1)));
                evt.setAccessId(Integer.parseInt(rs.getString(2)));
                evt.setTypeId(Integer.parseInt(rs.getString(3)));
                evt.setPosteddt(rs.getString(4));
                
                event.add(evt);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return event;
    }
public boolean eventupdatebyid(int eventid,int accessid) throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "UPDATE `tbl_event` SET `access_type`="+accessid+" WHERE event_id="+eventid;
  
        
        
        DBConnection db = new DBConnection();
        ArrayList<event> event=new ArrayList<event>();
        ResultSet rs;
        
        db.connect();
        try {
           db.executeQuery(Query);
                      
            
           
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return true;
    }

public ArrayList eventidbydate(String dat) throws SQLException, ClassNotFoundException         
    {
        String Query;
        
        
        
        Query = "select * from tbl_event where postedDt='"+dat+"';";
        
        
        DBConnection db = new DBConnection();
        ArrayList<event> event=new ArrayList<event>();
        ResultSet rs;
        
        db.connect();
        try {
            rs=db.customQuery(Query);
                      
            
           while(rs.next()){
                event evnt=new event();
                evnt.setEventId(Integer.parseInt(rs.getString(1)));
                evnt.setAccessId(Integer.parseInt(rs.getString(2)));
                evnt.setTypeId(Integer.parseInt(rs.getString(3)));
                evnt.setPosteddt(rs.getString(4));
                
                event.add(evnt);
                
                
            }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return event;
    }
  public boolean addeventquery(event newevent)         
    {
        String Query;
        
        
  
        
        Query = "INSERT INTO `tbl_event`(`event_id`, `access_type`, `type_id`, `postedDt`) VALUES (NULL,"+newevent.getAccessId() +","+ newevent.getTypeId() + ",'"+newevent.getPosteddt()+"');";
        
        //System.out.print(Query+"\n");
        DBConnection db = new DBConnection();
        db.connect();
        try {
            db.executeQuery(Query);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();
        
        
        return true;
    }
    public static void main(String args[])
    {
        
        try {
        
        
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
      
}
